package com.toocms.jinjuhang.ui.login.forget_password

import android.app.Application
import android.os.Bundle
import androidx.databinding.ObservableField
import com.toocms.jinjuhang.config.Constants
import com.toocms.jinjuhang.config.Urls
import com.toocms.jinjuhang.ui.login.LoginFgt
import com.toocms.jinjuhang.utils.FragmentUtils
import com.toocms.jinjuhang.widget.view_model.requestData
import com.toocms.tab.base.BaseModel
import com.toocms.tab.base.BaseViewModel
import com.toocms.tab.binding.command.BindingAction
import com.toocms.tab.binding.command.BindingCommand

class ForgetPasswordModel(application: Application, bundle: Bundle?) :
    BaseViewModel<BaseModel>(application) {
    val account by lazy {
        bundle?.getString(Constants.BundleKey.KEY_ACCOUNT) ?: ""
    }
    val verify by lazy {
        bundle?.getString(Constants.BundleKey.KEY_VERIFY) ?: ""
    }

    val passwordObservableField = ObservableField<String>()
    val rePasswordObservableField = ObservableField<String>()
    val confirmChangeClickBindingCommand = BindingCommand<BindingAction>(BindingAction {
        val params = mutableMapOf<String, String?>()
        params["account"] = account
        params["verify"] = verify
        params["password"] = passwordObservableField.get()
        params["re_password"] = rePasswordObservableField.get()
        requestData(Urls.Login.RETRIEVE, params, resultClass = String::class.java, result = {
            showToast(it)
            FragmentUtils.popTo(LoginFgt::class.java, false)
        })
    })

}